<?php
//模块名_控制名
class Customer_BalanceHistoryController extends Zend_Controller_Action
{

	public function preDispatch(){
		$this->tplDirectory = "customer/balance/";	//控制对应模板目录
	}
	
	public function indexAction(){
		$cbh_op_type = Customer_Service_BalanceHistory::$cbh_op_type;
		$cbh_op_type = array_slice($cbh_op_type,2);
		$this->view->cbh_op_type = $cbh_op_type;
		echo Cff::renderTpl($this->tplDirectory."balance-history.tpl","layout");	
    }
    
    public function listAction(){    	
    	$cond =array();   
    	$cbh_type_arr = Customer_Service_BalanceHistory::$cbh_type;
    	$cbh_op_type_arr = Customer_Service_BalanceHistory::$cbh_op_type;
    	$cbh_class_arr = Customer_Service_BalanceHistory::$cbh_class;
    	 	
		$customer_id = $this->_request->getParam('customer_id','');
		$cbh_refer_id = $this->_request->getParam('cbh_refer_id','');
		$cbh_op_type = $this->_request->getParam('cbh_op_type','');
		$dateFrom = $this->_request->getParam('dateFrom','');
		$dateTo = $this->_request->getParam('dateTo','');
		
		$customer_id && $cond['customer_id'] = $customer_id;
		$cbh_refer_id && $cond['cbh_refer_id'] = $cbh_refer_id;
		$cbh_op_type && $cond['cbh_op_type'] = $cbh_op_type;
		$dateFrom && $cond['dateFrom'] = $dateFrom;
		$dateTo && $cond['dateTo'] = $dateTo;
		
    	$page = $this->_request->getParam('page',1);
    	$pageSize = $this->_request->getParam('pageSize',20);
		$page = $page?$page:1;
    	$orderby = 'cbh_add_time desc';
    	
    	$total = Customer_Service_BalanceHistory::getByCondition($cond,'count(*)',$orderby, 0, 0);
		$result = Customer_Service_BalanceHistory::getByCondition($cond,'*',$orderby, $pageSize,$page);
		
		foreach ($result as $key => $val){
			$tmp_key = (string) $val['cbh_type'];
			$result[$key]['cbh_type'] = $cbh_type_arr[$val['cbh_type']];
			$result[$key]['cbh_op_type'] = $cbh_op_type_arr[$val['cbh_op_type']];
			$result[$key]['cbh_class'] = $cbh_class_arr[$val['cbh_class']];
		}
		$data=array('ask'=>0);
		if($total>0){
			$data=array(
				'total'=>$total,
				'result'=>$result,
				'ask'=>1
			);
		}
		die(Zend_Json::encode($data));
    }   
   
    
}